package com.wayne.service.impl;

import com.wayne.dao.AccountDao;
import com.wayne.model.Account;
import com.wayne.service.TransferService;

public class TransferServiceImpl implements TransferService {

  private AccountDao accountDao;

  public void setAccountDao(AccountDao accountDao) {
    this.accountDao = accountDao;
  }

  @Override
  public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
    Account from = accountDao.queryAccountByCardNo(fromCardNo);
    Account to = accountDao.queryAccountByCardNo(toCardNo);

    from.setMoney(from.getMoney() - money);
    to.setMoney(to.getMoney() + money);
    accountDao.updateAccountByCardNo(from);
    int i = 1 / 0;
    accountDao.updateAccountByCardNo(to);
  }
}
